﻿using System;
namespace Silverlight.PreLoading
{
    public interface IPreLoadingQueue
    {
        /// <summary>
        /// Adds a IPreLoadable object to the end of the queue
        /// </summary>
        /// <param name="key">A String used to reference the object in the queue</param>
        /// <param name="preLoadable">The IPreLoadable object to be queued</param>
        void Add(string key, IPreLoadable preLoadable);

        /// <summary>
        /// Gets or Sets a property indicating whether the queue should automatically begin downloading the next IPreLoadable in the queue once the current has finished downloading
        /// </summary>
        bool AutoAdvance { get; set; }

        /// <summary>
        /// Raised when the entire queue has completed preloading
        /// </summary>
        System.Collections.Generic.IEnumerable<IPreLoadable> Completed { get; }

        /// <summary>
        /// Gets the number of items that have so successfully completed preloading
        /// </summary>
        int CompletedCount { get; }

        /// <summary>
        /// Gets or Sets the maximum number of simultaneous connections the queue is allowed to open when preloading
        /// </summary>
        int ConnectionCount { get; set; }

        /// <summary>
        /// Gets the total number of items in the queue
        /// </summary>
        int Count { get; }

        /// <summary>
        /// Gets the collection of IPreLoadable objects that are currently downloading
        /// </summary>
        System.Collections.Generic.IEnumerable<IPreLoadable> Downloading { get; }

        /// <summary>
        /// Gets the number of IPreLoadable objects that are currently downloading
        /// </summary>
        int DownloadingCount { get; }

        /// <summary>
        /// Raised when an item in the queue fails to preload
        /// </summary>
        event EventHandler ItemFailed;

        /// <summary>
        /// Raised when an item in the queue has successfully completed preloading
        /// </summary>
        event EventHandler<LoadedEventArgs> OnItemPreLoaded;

        /// <summary>
        /// Advances to the next item in the queue and begins to preload it
        /// </summary>
        void LoadNext();

        /// <summary>
        /// Raised when a chunk of data is downloaded for an item currently being preloaded
        /// </summary>
        event EventHandler<PreLoadingProgressEventArgs> OnItemProgress;

        /// <summary>
        /// Sets the auto advance property to True and begins preloading at the next pending item
        /// </summary>
        void PreLoadAll();

        /// <summary>
        /// Gets the list of objects currently waiting to be downloading
        /// </summary>
        System.Collections.Generic.IEnumerable<IPreLoadable> Queue { get; }

        /// <summary>
        /// Gets the total preload progress for the entire queue as a double value between 0.0 and 1.0
        /// </summary>
        double TotalProgress { get; }
    }
}
